import * as api from "../../plugins/api.js"
import * as types from './mutation-types'

export const session = async function ({
  commit
}) {
  try {
    let data = await api.session()
    commit(types.SET_U, data)
    return true
  } catch (err) {
    return false
  }
}

export const login = async function ({
  commit
}, datas) {
  try {
    let data = await api.asynclogin(datas)
    commit(types.SET_U, data)
    return data
  } catch (err) {
    throw (err)
  }
}

export const actionschool = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetschool(datas)
    commit(types.SET_SCHOOL, data)
  } catch (err) {
    throw (err)
  }
}

export const actionschooladdress = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetallschooladdressbysid(datas)
    commit(types.SET_SCHOOLADDRESS, data)
  } catch (err) {
    throw (err)
  }
}

export const actionschooluser = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetallschooluserbysid(datas)
    commit(types.SET_SCHOOLUSER, data)
  } catch (err) {
    throw (err)
  }
}

export const actionschoolclassroom = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetallschoolclassroom(datas)
    data = data.map(v => {
      delete v.schooladdress
      return v
    })
    commit(types.SET_SCHOOLCLASSROOM, data)
  } catch (err) {
    throw (err)
  }
}

export const actionschoolrole = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetallschoolrolebysid(datas)
    commit(types.SET_SCHOOLROLE, data)
  } catch (err) {
    throw (err)
  }
}

export const actionschoolroletype = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetallschoolauthtype(datas)
    commit(types.SET_SCHOOLAUTHTYPE, data)
  } catch (err) {
    throw (err)
  }
}

export const actionschoolcourse = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetallschoolcoursebysid(datas)
    commit(types.SET_SCHOOLCOURSE, data)
  } catch (err) {
    throw (err)
  }
}

export const actionschoolclasshour = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetallschoolclasshour(datas)
    commit(types.SET_SCHOOLCLASSHOUR, data)
  } catch (err) {
    throw (err)
  }
}

export const actionschoolclazz = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetallschoolclazz(datas)
    commit(types.SET_SCHOOLCLAZZ, data)
  } catch (err) {
    throw (err)
  }
}


export const actionschoolholiday = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetschoolholiday(datas)
    commit(types.SET_SCHOOLHOLIDAY, data)
  } catch (err) {
    throw (err)
  }
}

export const actionschoolclasstime = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetschoolclasstime(datas)
    commit(types.SET_SCHOOLCLASSTIME, data)
  } catch (err) {
    throw (err)
  }
}

export const actionpackegekey = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetallpackegekey(datas)
    commit(types.SET_PACKEGEKEY, data)
  } catch (err) {
    throw (err)
  }
}

export const actionschoolstudent = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetallschoolstudent(datas)
    commit(types.SET_SCHOOLSTUDENT, data)
  } catch (err) {
    throw (err)
  }
}


export const actionschoolhomework = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetschoolhomework(datas)
    commit(types.SET_SCHOOLHOMEWORK, data)
  } catch (err) {
    throw (err)
  }
}

export const actionschoolannouncementpush = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetschoolannouncementpush(datas)
    commit(types.SET_SCHOOANNOUNCEMENTPUSH, data)
  } catch (err) {
    throw (err)
  }
}

export const actionschoolitembankgroup = async function ({
  commit
}, datas) {
  try {
    let data = await api.asyncgetschoolitembankgroup(datas)
    commit(types.SET_SCHOOLITEMBANKGROUP, data)
  } catch (err) {
    throw (err)
  }
}
